package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘远望
 * Date: 2025-05-22
 * Time: 21:49
 */
//join等待线程
public class Demo12 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
           for (int i = 0; i < 30; i++) {
               System.out.println("hello thread");
               try {
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
            System.out.println("thread 线程结束");
        });

        thread.start();

        //thread.join();
        //thread.join(3000);//超时间等待 超过这个时间就不会在等待就会继续执行
        thread.join(3000, 500);//第二个参数纳秒(精度) 基本用不到 s ms us ns
        System.out.println("main线程结束");
    }
}
